package common.struct;

import com.alibaba.fastjson.JSONObject;
import platform.service.inv.InvLine;

import java.util.HashMap;
import java.util.Map;

public class InvServiceResult implements ServiceResult {
    Map<String, Object> invs;

    public InvServiceResult(Map<String, Object> invs) {
        this.invs = invs;
    }
    //TODO
    @Override
    public String toJSONString() {
        return toJSONObject().toJSONString();
    }

    @Override
    public JSONObject toJSONObject() {
        JSONObject joo = new JSONObject();
        for (Map.Entry<String, Object> entry : invs.entrySet()) {
            joo.put(entry.getKey().toString(), entry.getValue());
        }
        return joo;
    }

    public static InvServiceResult fromJSONString(String json) {
        JSONObject jo = JSONObject.parseObject(json);
        Map<String, Object> invs = new HashMap<>(jo);
        return new InvServiceResult(invs);
    }
}
